/*
 * Main.java
 *
 * Created on 19 de Maio de 2007, 20:17
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.jerm.Interface;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;

import java.util.ArrayList;

import org.jerm.Conectividade.RetornoSQL;
import org.jerm.Conectividade.SGBD;
import org.jerm.Interface.JGraph_Diagrama.Aresta;
import org.jerm.Interface.JGraph_Diagrama.BlocoAtributosGraphCell;
import org.jerm.Interface.JGraph_Diagrama.Entidade;
import org.jerm.Interface.JGraph_Diagrama.Heranca;
import org.jerm.Interface.JGraph_Diagrama.MyGraph;
import org.jerm.Interface.JGraph_Diagrama.Relacionamento;
import org.jerm.Mapeamento.Atributos.Atributo;
import org.jgraph.JGraph;
import org.jgraph.graph.DefaultEdge;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultGraphModel;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphModel;
import org.jgraph.graph.GraphUndoManager;

import javax.swing.text.NumberFormatter;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.beans.*;

import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.beans.BeanInfo;
import java.beans.DefaultPersistenceDelegate;
import java.beans.Encoder;
import java.beans.ExceptionListener;
import java.beans.Expression;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PersistenceDelegate;
import java.beans.PropertyDescriptor;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JToolBar;
import javax.swing.JViewport;
import javax.swing.filechooser.FileFilter;

import org.jgraph.JGraph;
import org.jgraph.event.GraphSelectionEvent;
import org.jgraph.graph.AbstractCellView;
import org.jgraph.graph.AttributeMap;
import org.jgraph.graph.BasicMarqueeHandler;
import org.jgraph.graph.DefaultCellViewFactory;
import org.jgraph.graph.DefaultEdge;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultGraphModel;
import org.jgraph.graph.DefaultPort;
import org.jgraph.graph.EdgeView;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphLayoutCache;
import org.jgraph.graph.GraphModel;
import org.jgraph.graph.ParentMap;
import org.jgraph.graph.PortView;
import org.jgraph.graph.VertexView;

/**
 *
 * @author Tiago Falcao
 */
public class Principal extends javax.swing.JFrame
                       implements   ActionListener
                                    //ChangeListener,
                                    //PropertyChangeListener
{
    private String Nome=" - DBModel Koyte";
    public String Projeto="DBModel";
    public int Versao=0;
    
    public SGBD SGBD_ALVO=null;
    public SGBD SGBD_BASE=null;
    
    /********************** MenuBar *******************************************/
    private JMenuBar menuBar;
    
    private JMenu menu_Projeto;
    private JMenuItem menu_Projeto_Novo;
    private JMenuItem menu_Projeto_Abrir;
    private JMenuItem menu_Projeto_Salvar_arq;
    private JMenuItem menu_Projeto_Salvar_bd;
    private JMenuItem menu_Projeto_Salvarcomo;
    private JMenuItem menu_Projeto_Exportar;
    private JMenuItem menu_Projeto_Sair;
    
    private JMenu menu_Editar;
    
    private JMenu menu_Ajuda;
    private JMenuItem menu_Ajuda_Ajuda;
    private JMenuItem menu_Ajuda_Sobre;
    
    /*********************** Abas *********************************************/
    public JTabbedPane Abas;
    
    private Diagrama_Aba Diagrama;
    private String  Diagrama_toolTip;
    public Tabelas Tabelas;
    private String  Tabelas_toolTip;
    private Algebra Algebra;
    private String  Algebra_toolTip;
    public Consultas Consultas;
    private String  Consultas_toolTip;
    private Configuracoes Configuracoes;
    private String  Configuracoes_toolTip;
    
    /*********************** Diagrama   **************************************/
    private MyGraph graph;
    /*********************** Zoom        **************************************/
//    private JPanel ZOOM_Panel;
//    private static final int ZOOM_MIN = 0;
//    private static final int ZOOM_MAX = 300;
//    private static final int ZOOM_INIT = 100;
//    private JSlider ZOOM_Slider;
//    private JLabel ZOOM_sliderLabel;
//    private java.text.NumberFormat ZOOM_numberFormat;
//    private NumberFormatter ZOOM_Formatter;
//    private JFormattedTextField ZOOM_TextField;
    //Abrir Salvar
    protected JFileChooser fileChooser = null;
    
    /**************************************************************************/
    
    /** Creates a new instance of Main */
    public Principal ()
    {
        super("DBModel Koyte");
        
        setIconImage(new ImageIcon(Principal.class.getResource("Icones/icon.png")).getImage());//Icone
        setDefaultLookAndFeelDecorated(false); //Tema de Janela igual ao do Windows

        //Faz a Janela Ficar Identada 50 pixels para cada borda da tela
        int inset = 50;
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds(inset, inset,
                  screenSize.width  - inset*2,
                  screenSize.height - inset*2);

        //Cria o Desktop de Janelas
        //desktop = new JDesktopPane(); //a specialized layered pane
        //setContentPane(desktop);
        
        //Aparetemente fecha tudo sem pedir para salvar
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        
    /********************** MenuBar *******************************************/
        this.createMenuBar ();
        setJMenuBar(menuBar);        
        
        
    /*********************** Abas *********************************************/
        //Abas
        createAbas();
        add(Abas);
        
        
    ////// SGBDs
        SGBD_ALVO=new SGBD();
        SGBD_BASE=new SGBD();
        //Somente para Testes valores Padroes
//        SGBD_ALVO=new SGBD("mysql","tognado.homelinux.org","mc536","rtorres","3306","mc536g04_alvo");
//        SGBD_BASE=new SGBD("mysql","tognado.homelinux.org","mc536","rtorres","3306","mc536_proj2");
//        
//        SGBD_ALVO.Conecta();
//        SGBD_BASE.Conecta();
        Configuracoes.restaurar();
    }
    
    /** Creates a new instance of Main */
    public Principal (String Projeto,SGBD base)
    {
        this();
        this.Projeto=Projeto;
        SGBD_BASE=base;
        importSGBD();
        setVisible(true);
    }
    
    public Consultas getConsultas()
    {
        return this.Consultas;
    }
    
    protected void createMenuBar() {
        menuBar = new JMenuBar();
        
        //Projeto
        menu_Projeto = new JMenu("Projeto");
        menu_Projeto.setMnemonic(KeyEvent.VK_P);
        menuBar.add(menu_Projeto);

        //Novo
        menu_Projeto_Novo = new JMenuItem("Novo");
        menu_Projeto_Novo.setMnemonic(KeyEvent.VK_N);
        menu_Projeto_Novo.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_N, ActionEvent.ALT_MASK));
        menu_Projeto_Novo.setActionCommand("menu_Projeto_Novo");
        menu_Projeto_Novo.addActionListener(this);
        menu_Projeto.add(menu_Projeto_Novo);

        //Novo
        menu_Projeto_Abrir = new JMenuItem("Abrir Arquivo");
        menu_Projeto_Abrir.setMnemonic(KeyEvent.VK_O);
        menu_Projeto_Abrir.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_R, ActionEvent.CTRL_MASK));
        menu_Projeto_Abrir.setActionCommand("menu_Projeto_Abrir");
        menu_Projeto_Abrir.addActionListener(this);
        menu_Projeto.add(menu_Projeto_Abrir);

        //Novo
        menu_Projeto_Abrir = new JMenuItem("Abrir do BD");
        menu_Projeto_Abrir.setMnemonic(KeyEvent.VK_B);
        menu_Projeto_Abrir.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_O, ActionEvent.CTRL_MASK));
        menu_Projeto_Abrir.setActionCommand("menu_Projeto_AbrirBD");
        menu_Projeto_Abrir.addActionListener(this);
        menu_Projeto.add(menu_Projeto_Abrir);

        //Novo
        menu_Projeto_Salvar_arq = new JMenuItem("Salvar Arq");
        menu_Projeto_Salvar_arq.setMnemonic(KeyEvent.VK_S);
        menu_Projeto_Salvar_arq.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_A, ActionEvent.CTRL_MASK));
        menu_Projeto_Salvar_arq.setActionCommand("menu_Projeto_Salvar_arq");
        menu_Projeto_Salvar_arq.addActionListener(this);
        menu_Projeto.add(menu_Projeto_Salvar_arq);

        //Novo
        menu_Projeto_Salvar_bd = new JMenuItem("Salvar para BD");
        menu_Projeto_Salvar_bd.setMnemonic(KeyEvent.VK_A);
        menu_Projeto_Salvar_bd.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_S, ActionEvent.CTRL_MASK));
        menu_Projeto_Salvar_bd.setActionCommand("menu_Projeto_Salvar_bd");
        menu_Projeto_Salvar_bd.addActionListener(this);
        menu_Projeto.add(menu_Projeto_Salvar_bd);
        
        //Novo
        menu_Projeto_Exportar = new JMenuItem("Exportar");
        menu_Projeto_Exportar.setMnemonic(KeyEvent.VK_S);
        menu_Projeto_Exportar.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_X, ActionEvent.ALT_MASK));
        menu_Projeto_Exportar.setActionCommand("menu_Projeto_Exportar");
        menu_Projeto_Exportar.addActionListener(this);
        menu_Projeto.add(menu_Projeto_Exportar);

        //Sair
        menu_Projeto_Sair = new JMenuItem("Fechar");
        menu_Projeto_Sair.setMnemonic(KeyEvent.VK_F);
        menu_Projeto_Sair.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_F4, ActionEvent.ALT_MASK));
        menu_Projeto_Sair.setActionCommand("menu_Projeto_Sair");
        menu_Projeto_Sair.addActionListener(this);
        menu_Projeto.add(menu_Projeto_Sair);
        
        
        
        
        
        //Ajuda
        menu_Ajuda = new JMenu("Ajuda");
        menu_Ajuda.setMnemonic(KeyEvent.VK_A);
        menuBar.add(menu_Ajuda);

        //Ajuda
        menu_Ajuda_Ajuda = new JMenuItem("Ajuda");
        menu_Ajuda_Ajuda.setMnemonic(KeyEvent.VK_A);
        menu_Ajuda_Ajuda.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_F1, 0));
        menu_Ajuda_Ajuda.setActionCommand("menu_Ajuda_Ajuda");
        menu_Ajuda_Ajuda.addActionListener(this);
        menu_Ajuda.add(menu_Ajuda_Ajuda);

        //Sobre
        menu_Ajuda_Sobre = new JMenuItem("Sobre");
        menu_Ajuda_Sobre.setMnemonic(KeyEvent.VK_S);
        menu_Ajuda_Sobre.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_S, ActionEvent.ALT_MASK));
        menu_Ajuda_Sobre.setActionCommand("menu_Ajuda_Sobre");
        menu_Ajuda_Sobre.addActionListener(this);
        menu_Ajuda.add(menu_Ajuda_Sobre);
        
    }
    
    protected void createAbas(){
        Abas = new JTabbedPane();
        
        Diagrama=new Diagrama_Aba(this);
        this.graph=Diagrama.getGraph();
        Diagrama_toolTip=Diagrama.getToolTip ();
        Abas.addTab ("Diagrama",new ImageIcon(getClass().getClassLoader().getResource("org/jerm/Interface/Icones/diagrama.png")),Diagrama,Diagrama_toolTip);
        
        Tabelas=new Tabelas(graph,this);
        Tabelas_toolTip=Tabelas.getToolTip();
        Abas.addTab ("Tabelas",new ImageIcon(getClass().getClassLoader().getResource("org/jerm/Interface/Icones/mapeamento.png")),Tabelas,Tabelas_toolTip);
        Tabelas.updateUI();
        
        Algebra=new Algebra(this);
        Algebra_toolTip=Algebra.getToolTip();
        Abas.addTab ("Algebra",new ImageIcon(getClass().getClassLoader().getResource("org/jerm/Interface/Icones/algebra.png")),Algebra,Algebra_toolTip);
        
        Consultas=new Consultas(this);
        Consultas_toolTip=Consultas.getToolTip();
        Abas.addTab ("Consultas",new ImageIcon(getClass().getClassLoader().getResource("org/jerm/Interface/Icones/consultas.png")),Consultas,Consultas_toolTip);
        
        Configuracoes=new Configuracoes(this);
        Configuracoes_toolTip=Configuracoes.getToolTip();
        Abas.addTab ("Configuracoes",new ImageIcon(getClass().getClassLoader().getResource("org/jerm/Interface/Icones/configuracoes.png")),Configuracoes,Configuracoes_toolTip);
        //Configuracoes.restaurar();
        
        Abas.setSelectedIndex(4);
        
        Abas.addChangeListener(new ChangeListener() {
                    // This method is called whenever the selected tab changes
                    public void stateChanged(ChangeEvent evt) {
                        JTabbedPane pane = (JTabbedPane)evt.getSource();

                        // Get current tab
                        int sel = pane.getSelectedIndex();
                        if(sel==4){
                            Configuracoes.restaurar();
                        }
                    }
        });
    }
    
//    protected void createZoom(){
//        ZOOM_sliderLabel = new JLabel("ZOOM: ", JLabel.CENTER);
//        ZOOM_sliderLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
//
//        //Create the formatted text field and its formatter.
//        ZOOM_numberFormat = java.text.NumberFormat.getIntegerInstance();
//        ZOOM_Formatter = new NumberFormatter(ZOOM_numberFormat);
//        ZOOM_Formatter.setMinimum(new Integer(ZOOM_MIN));
//        ZOOM_Formatter.setMaximum(new Integer(ZOOM_MAX));
//        ZOOM_TextField = new JFormattedTextField(ZOOM_Formatter);
//        ZOOM_TextField.setValue(new Integer(ZOOM_INIT));
//        ZOOM_TextField.setColumns(5); //get some space
//        ZOOM_TextField.addPropertyChangeListener(this);
//        
//        //React when the user presses Enter.
//        ZOOM_TextField.getInputMap().put(KeyStroke.getKeyStroke(
//                                        KeyEvent.VK_ENTER, 0),
//                                        "check");
//        ZOOM_TextField.getActionMap().put("check", new AbstractAction() {
//            public void actionPerformed(ActionEvent e) {
//                if (!ZOOM_TextField.isEditValid()) { //The text is invalid.
//                    Toolkit.getDefaultToolkit().beep();
//                    ZOOM_TextField.selectAll();
//                } else try {                    //The text is valid,
//                    ZOOM_TextField.commitEdit();     //so use it.
//                } catch (java.text.ParseException exc) { }
//            }
//        });
//        
//        
//        
//        ZOOM_Slider = new JSlider(JSlider.HORIZONTAL,
//                                      ZOOM_MIN, ZOOM_MAX, ZOOM_INIT);
//        ZOOM_Slider.addChangeListener(this);
//
//        //Turn on labels at major tick marks.
//        ZOOM_Slider.setMajorTickSpacing(100);
//        ZOOM_Slider.setMinorTickSpacing(25);
//        //ZOOM_Slider.setPaintTicks(true);
//        //ZOOM_Slider.setPaintLabels(true);
//        //ZOOM_Slider.setBorder(
//        //        BorderFactory.createEmptyBorder(0,0,5,0));
//        
//        ZOOM_Panel = new JPanel();
//        ZOOM_Panel.add(ZOOM_sliderLabel);
//        ZOOM_Panel.add(ZOOM_Slider);
//        ZOOM_Panel.add(ZOOM_TextField);
//        
//        Diagrama_Tools.add(ZOOM_Panel);
//    }
    
//    public void stateChanged(ChangeEvent e) {
//        JSlider source = (JSlider)e.getSource();
//        int zoom = (int)source.getValue();
//        if (!source.getValueIsAdjusting()) { //done adjusting
//            ZOOM_TextField.setValue(new Integer(zoom)); //update ftf value
//            graph.setScale(((double)zoom)/100);
//        } else { //value is adjusting; just set the text
//            ZOOM_TextField.setText(String.valueOf(zoom));
//        }
//    }
    
//    public void propertyChange(PropertyChangeEvent e) {
//        if ("value".equals(e.getPropertyName())) {
//            Number value = (Number)e.getNewValue();
//            if (ZOOM_Slider != null && value != null) {
//                ZOOM_Slider.setValue(value.intValue());
//            }
//        }
//    }
    
    public void saveFile() {
//            int returnValue = JFileChooser.CANCEL_OPTION;
//            initFileChooser();
//            returnValue = fileChooser.showSaveDialog(graph);
//            if (returnValue == JFileChooser.APPROVE_OPTION) {
//                    XMLEncoder encoder;
//                    Container parent = graph.getParent();
//                    try {
//                            //uninstallListeners(graph);
//                            parent.remove(graph);
//                            encoder = new XMLEncoder(new BufferedOutputStream(
//                                            new FileOutputStream(fileChooser.getSelectedFile())));
//                            configureEncoder(encoder);
//                            encoder.writeObject(graph);
//                            encoder.close();
//                    } catch (Exception e) {
//                            JOptionPane.showMessageDialog(graph, e.getMessage(), "Error",
//                                            JOptionPane.ERROR_MESSAGE);
//                    } finally {
//                            // Adds the component back into the component hierarchy
//                            if (parent instanceof JViewport) {
//                                    JViewport viewPort = (JViewport) parent;
//                                    viewPort.setView(graph);
//                            } else {
//                                    // Best effort...
//                                    parent.add(graph);
//                            }
//                            // And reinstalls the listener
//                            //installListeners(graph);
//                    }
//            }
    }
    
    protected void configureEncoder(XMLEncoder encoder) {
//        // Better debugging output, in case you need it
//        encoder.setExceptionListener(new ExceptionListener() {
//                public void exceptionThrown(Exception e) {
//                        e.printStackTrace();
//                }
//        });
//
//        encoder.setPersistenceDelegate(DefaultGraphModel.class,
//                        new DefaultPersistenceDelegate(new String[] { "roots",
//                                        "attributes" }));
//        encoder.setPersistenceDelegate(GraphModel.class,
//                        new DefaultPersistenceDelegate(new String[] { "roots",
//                                        "attributes" }));
//
//        // Note: In the static initializer the marquee handler of the
//        // MyGraph class is made transient to avoid being written out.
//        encoder.setPersistenceDelegate(JGraph.class,
//                        new DefaultPersistenceDelegate(new String[] { "model",
//                                        "graphLayoutCache" }));
//        encoder.setPersistenceDelegate(GraphLayoutCache.class,
//                                        new DefaultPersistenceDelegate(new String[] { "model",
//                                                        "factory", "cellViews", "hiddenCellViews",
//                                                        "partial" }));
//        encoder.setPersistenceDelegate(DefaultGraphCell.class,
//                        new DefaultPersistenceDelegate(new String[] { "userObject" }));
//        encoder.setPersistenceDelegate(DefaultEdge.class,
//                        new DefaultPersistenceDelegate(new String[] { "userObject" }));
//        encoder.setPersistenceDelegate(DefaultPort.class,
//                        new DefaultPersistenceDelegate(new String[] { "userObject" }));
//        encoder.setPersistenceDelegate(AbstractCellView.class,
//                        new DefaultPersistenceDelegate(new String[] { "cell",
//                                        "attributes" }));
//        encoder.setPersistenceDelegate(DefaultEdge.DefaultRouting.class,
//                        new PersistenceDelegate() {
//                                protected Expression instantiate(Object oldInstance,
//                                                Encoder out) {
//                                        return new Expression(oldInstance,
//                                                        GraphConstants.class, "getROUTING_SIMPLE", null);
//                                }
//                        });
//        encoder.setPersistenceDelegate(DefaultEdge.LoopRouting.class,
//                        new PersistenceDelegate() {
//                                protected Expression instantiate(Object oldInstance,
//                                                Encoder out) {
//                                        return new Expression(oldInstance,
//                                                        GraphConstants.class, "getROUTING_DEFAULT",
//                                                        null);
//                                }
//                        });
//                        
//        encoder.setPersistenceDelegate(ArrayList.class, encoder
//                        .getPersistenceDelegate(List.class));
    }
    
    public void openFile() {
//        int returnValue = JFileChooser.CANCEL_OPTION;
//        initFileChooser();
//        returnValue = fileChooser.showOpenDialog(graph);
//        if (returnValue == JFileChooser.APPROVE_OPTION) {
//                Container parent = graph.getParent();
//                BasicMarqueeHandler marqueeHandler = graph.getMarqueeHandler();
//                try {
//                        //uninstallListeners(graph);
//                        parent.remove(graph);
//                        XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(
//                                        new FileInputStream(fileChooser.getSelectedFile())));
//                        graph = (JGraph) decoder.readObject();
//                        // Take the marquee handler from the original graph and
//                        // use it in the new graph as well.
//                        graph.setMarqueeHandler(marqueeHandler);
//                        // Adds the component back into the component hierarchy
//                        if (parent instanceof JViewport) {
//                                JViewport viewPort = (JViewport) parent;
//                                viewPort.setView(graph);
//                        } else {
//                                // Best effort...
//                                parent.add(graph);
//                        }
//                        // graph.setMarqueeHandler(previousHandler);
//                        // And reinstalls the listener
//                        //installListeners(graph);
//                } catch (FileNotFoundException e) {
//                        JOptionPane.showMessageDialog(graph, e.getMessage(), "Error",
//                                        JOptionPane.ERROR_MESSAGE);
//                }
//
//            }
	}
    
    protected void initFileChooser() {
            if (fileChooser == null) {
                    fileChooser = new JFileChooser();
                    FileFilter fileFilter = new FileFilter() {
                            /**
                             * @see javax.swing.filechooser.FileFilter#accept(File)
                             */
                            public boolean accept(File f) {
                                    if (f == null)
                                            return false;
                                    if (f.getName() == null)
                                            return false;
                                    if (f.getName().endsWith(".xml"))
                                            return true;
                                    //if (f.getName().endsWith(".ser"))
                                   //         return true;
                                    if (f.isDirectory())
                                            return true;

                                    return false;
                            }

                            /**
                             * @see javax.swing.filechooser.FileFilter#getDescription()
                             */
                            public String getDescription() {
                                    return "Arquivos DB BBE (.xml)";
                            }
                    };
                    fileChooser.setFileFilter(fileFilter);
            }
    }
    
    public void actionPerformed(ActionEvent e) {
        if ("menu_Ajuda_Ajuda".equalsIgnoreCase(e.getActionCommand())) { //new
            System.out.println ("Ajuda nada!!!\n");
        }else if ("menu_Ajuda_Sobre".equals(e.getActionCommand())) { //new
            System.out.println ("Sobre nada!!!\n");
            //new Sobre (new javax.swing.JFrame (), true).setVisible (true);
        }else if ("menu_Projeto_Novo".equalsIgnoreCase(e.getActionCommand())) { //new
            new Principal().setVisible(true);
        }else if ("menu_Projeto_Abrir".equalsIgnoreCase(e.getActionCommand())) { //new
            openFile();
        }else if ("menu_Projeto_AbrirBD".equalsIgnoreCase(e.getActionCommand())) { //new
            new OpenBD(false);
        }else if ("menu_Projeto_Salvar_arq".equalsIgnoreCase(e.getActionCommand())) { //new
            saveFile();
        }else if ("menu_Projeto_Salvar_bd".equalsIgnoreCase(e.getActionCommand())) { //new
            exportSGBD();
        }else if ("menu_Projeto_Exportar".equalsIgnoreCase(e.getActionCommand())) { //new
            graph.exportImage();
        }else{
            setVisible(false);
            dispose();
        }
        //if ("new".equals(e.getActionCommand())) { //new
        //    createFrame();
        //} else { //quit
        //    quit();
        //}
    }
    
    public String boo2str(boolean b){
        if(b)
            return "1";
        else
            return "0";
    }
    
    
        //////////////////////////////////////////////////////////////////////////////
    //
    // Import
    //
    public void importSGBD(){
        ArrayList<Entidade> Entidades= new ArrayList();
        ArrayList<Relacionamento> Relacionamentos= new ArrayList();
        ArrayList<Heranca> Herancas= new ArrayList();
        Object[] edges=graph.getGraphLayoutCache().getCells(false,true,false,false);
        
        RetornoSQL r=new RetornoSQL();
        r=this.SGBD_BASE.executaSQL("SELECT MAX(Versao) FROM Projetos WHERE Nome='"+Projeto+"';","query");
        if(r!=null){
            try {
                ResultSet rs=r.getResultSet();
                rs.first();
                Versao=rs.getInt("MAX(Versao)");
            } catch (SQLException ex) {
                new Error("SQL Error "+ex.getErrorCode()+"\n"+ex.getMessage());
                //ex.printStackTrace();
                new OpenBD(true);
                dispose();
            }
        }
        
        String SQL="SELECT SGBD,URL,Porta,BD,Usuario FROM Alvos WHERE Projeto='"+Projeto+"' AND Versao='"+Integer.toString(Versao)+"';";
        r=this.SGBD_BASE.executaSQL(SQL,"query");
        if(r==null){
            new Error("Erro ao recuperar dados do banco de dados Alvo.");
            return;
        }else{
            try {
                ResultSet rs=r.getResultSet();
                rs.first();
                SGBD_ALVO.setSGBD(rs.getString("SGBD"));
                SGBD_ALVO.setServidor(rs.getString("URL"));
                SGBD_ALVO.setPorta(rs.getString("Porta"));
                SGBD_ALVO.setBD(rs.getString("BD"));
                SGBD_ALVO.setUsuario(rs.getString("Usuario"));
            } catch (SQLException ex) {
                new Error("Erro ao recuperar dados do banco de dados Alvo.\nSQL Error "+ex.getErrorCode()+"\n"+ex.getMessage());
                //ex.printStackTrace();
                new OpenBD(true);
                dispose();
            }
        }
        Configuracoes.restaurar();
        
        
        SQL="SELECT ID,Nome,Fraca,x,y,w,h FROM Entidades WHERE Projeto='"+Projeto+"' AND Versao='"+Integer.toString(Versao)+"' ORDER BY ID ASC;";
        //System.out.println(SQL+"\n");
        r=this.SGBD_BASE.executaSQL(SQL,"query");
        if(r==null){
            new Error("Erro ao recuperar entidades.");
            return;
        }else{
            //SQL="SELECT SGBD,URL,Porta,BD,Usuario FROM Entidades WHERE Projeto='"+Projeto+"' AND Versao='"+Integer.toString(Versao)+"' ORDER BY ID ASC;";
            try {
                ResultSet rs=r.getResultSet();
                Entidade e=null;
                boolean boo;
                int id;
                ResultSet rs2=null;
                rs.beforeFirst();
                while(rs.next()){
                    e=new Entidade(rs.getDouble("x"),rs.getDouble("y"),rs.getDouble("w"),rs.getDouble("h"),Color.white,rs.getString("Nome"));
                    //System.out.println(rs.getString("Nome"));
                    boo=rs.getBoolean("Fraca");
                    e.setFraca(boo);
                    id=rs.getInt("ID");
                    graph.getGraphLayoutCache().insert(e);
                    Entidades.add(e);
                }
            } catch (SQLException ex) {
                new Error("Erro ao recuperar entidades.\nSQL Error "+ex.getErrorCode()+"\n"+ex.getMessage());
                //ex.printStackTrace();
                new OpenBD(true);
                dispose();
            }
        }
        
        
        SQL="SELECT ID,Nome,Associativa,Total,x,y,w,h FROM Relacionamentos WHERE Projeto='"+Projeto+"' AND Versao='"+Integer.toString(Versao)+"' ORDER BY ID ASC;";
        //System.out.println(SQL+"\n");
        r=this.SGBD_BASE.executaSQL(SQL,"query");
        if(r==null){
            new Error("Erro ao recuperar relacionamentos.");
            return;
        }else{
            //SQL="SELECT SGBD,URL,Porta,BD,Usuario FROM Entidades WHERE Projeto='"+Projeto+"' AND Versao='"+Integer.toString(Versao)+"' ORDER BY ID ASC;";
            try {
                ResultSet rs=r.getResultSet();
                Relacionamento e=null;
                boolean boo;
                int id;
                ResultSet rs2=null;
                rs.beforeFirst();
                while(rs.next()){
                    e=new Relacionamento(rs.getDouble("x"),rs.getDouble("y"),rs.getDouble("w"),rs.getDouble("h"),Color.white,rs.getString("Nome"));
                    //System.out.println(rs.getString("Nome"));
                    boo=rs.getBoolean("Associativa");
                    e.setAssociativa(boo);
                    boo=rs.getBoolean("Total");
                    e.setTotal(boo);
                    id=rs.getInt("ID");
                    graph.getGraphLayoutCache().insert(e);
                    Relacionamentos.add(e);
                }
            } catch (SQLException ex) {
                new Error("Erro ao recuperar relacionamentos.\nSQL Error "+ex.getErrorCode()+"\n"+ex.getMessage());
                //ex.printStackTrace();
                new OpenBD(true);
                dispose();
            }
        }
        
        
        SQL="SELECT ID,Disjunta,Total,x,y,w,h FROM Herancas WHERE Projeto='"+Projeto+"' AND Versao='"+Integer.toString(Versao)+"' ORDER BY ID ASC;";
        //System.out.println(SQL+"\n");
        r=this.SGBD_BASE.executaSQL(SQL,"query");
        if(r==null){
            new Error("Erro ao recuperar herancas.");
            return;
        }else{
            //SQL="SELECT SGBD,URL,Porta,BD,Usuario FROM Entidades WHERE Projeto='"+Projeto+"' AND Versao='"+Integer.toString(Versao)+"' ORDER BY ID ASC;";
            try {
                ResultSet rs=r.getResultSet();
                Heranca e=null;
                boolean boo;
                int id;
                rs.beforeFirst();
                while(rs.next()){
                    e=new Heranca(rs.getDouble("x"),rs.getDouble("y"),rs.getDouble("w"),rs.getDouble("h"),Color.white,"");
                    boo=rs.getBoolean("Disjunta");
                    e.setDisjunta(boo);
                    boo=rs.getBoolean("Total");
                    e.setTotal(boo);
                    id=rs.getInt("ID");
                    graph.getGraphLayoutCache().insert(e);
                    Herancas.add(e);
                }
            } catch (SQLException ex) {
                new Error("Erro ao recuperar herancas.\nSQL Error "+ex.getErrorCode()+"\n"+ex.getMessage());
                //ex.printStackTrace();
                new OpenBD(true);
                dispose();
            }
        }
        
        
        SQL="SELECT ID,Heranca,Total,Source,Target,Source_type,Target_type,Min,Max FROM Arestas WHERE Projeto='"+Projeto+"' AND Versao='"+Integer.toString(Versao)+"' ORDER BY ID ASC;";
        //System.out.println(SQL+"\n");
//        System.out.println("Entidades="+new Integer(Entidades.size()).toString()+"\n"+
//                "Relacionamentos="+new Integer(Relacionamentos.size()).toString()+"\n"+
//                "Herancas="+new Integer(Herancas.size()).toString());
        r=this.SGBD_BASE.executaSQL(SQL,"query");
        if(r==null){
//            System.out.println("ERRO");
            new Error("Erro ao recuperar linhas.");
            return;
        }else{
            //SQL="SELECT SGBD,URL,Porta,BD,Usuario FROM Entidades WHERE Projeto='"+Projeto+"' AND Versao='"+Integer.toString(Versao)+"' ORDER BY ID ASC;";
            try {
//            System.out.println("SUCESSO");
                ResultSet rs=r.getResultSet();
                Aresta e=null;
                boolean boo;
                int id;
                int s;
                int t;
                String st,tt;
                rs.beforeFirst();
                while(rs.next()){
                    e=new Aresta();
                    
                    boo=rs.getBoolean("Heranca");
                    if(boo)
                        e.setHeranca();
                    else{
                        e.setCardinalidade(rs.getInt("Min"),rs.getInt("Max"));
                    }
                    boo=rs.getBoolean("Total");
                    e.setTotal(boo);
                    id=rs.getInt("ID");
                    st=rs.getString("Source_type");
//                    System.out.println(st+" "+new Integer(rs.getInt("Source")).toString());
                    if(st.equalsIgnoreCase("Entidade")){
                        e.setSource((DefaultPort)Entidades.get(rs.getInt("Source")).getChildAt(0));
//                        //System.out.println(graph.convertValueToString(Entidades.get(rs.getInt("Source"))));
                    }else if(st.equalsIgnoreCase("Relacionamento")){
                        e.setSource((DefaultPort)Relacionamentos.get(rs.getInt("Source")).getChildAt(0));
//                        System.out.println(graph.convertValueToString(Relacionamentos.get(rs.getInt("Source"))));
                    }else if(st.equalsIgnoreCase("Heranca")){
                        e.setSource((DefaultPort)Herancas.get(rs.getInt("Source")).getChildAt(0));
//                        System.out.println(graph.convertValueToString(Herancas.get(rs.getInt("Source"))));
                    }//else{
//                        System.out.println("ERRO!!!! "+st);
//                    }
                    tt=rs.getString("Target_type");
//                    System.out.println(tt+" "+new Integer(rs.getInt("Target")).toString());
                    if(tt.equalsIgnoreCase("Entidade")){
                        e.setTarget((DefaultPort)Entidades.get(rs.getInt("Target")).getChildAt(0));
//                        System.out.println(graph.convertValueToString(Entidades.get(rs.getInt("Target"))));
                    }else if(tt.equalsIgnoreCase("Relacionamento")){
                        e.setTarget((DefaultPort)Relacionamentos.get(rs.getInt("Target")).getChildAt(0));
//                        System.out.println(graph.convertValueToString(Relacionamentos.get(rs.getInt("Target"))));
                    }else if(tt.equalsIgnoreCase("Heranca")){
                        e.setTarget((DefaultPort)Herancas.get(rs.getInt("Target")).getChildAt(0));
//                        System.out.println(graph.convertValueToString(Herancas.get(rs.getInt("Target"))));
                    }//else{
//                        System.out.println("ERRO!!!! "+tt);
//                    }
                    graph.getGraphLayoutCache().insert(e);
                }
            } catch (SQLException ex) {
                new Error("Erro ao recuperar linhas.\nSQL Error "+ex.getErrorCode()+"\n"+ex.getMessage());
                //ex.printStackTrace();
                new OpenBD(true);
                dispose();
            }
        }
        
        
        
        graph.updateUI();
        
    }
    
        //////////////////////////////////////////////////////////////////////////////
    //
    // Export
    //
    public void exportSGBD(){
        ArrayList<Entidade> Entidades= new ArrayList();
        ArrayList<Relacionamento> Relacionamentos= new ArrayList();
        ArrayList<Heranca> Herancas= new ArrayList();
        Object[] edges=graph.getGraphLayoutCache().getCells(false,true,false,false);
        
        RetornoSQL r=null;
        String SQL="SELECT MAX(Versao) FROM Projetos WHERE Projeto='"+Projeto+"';";
        r=this.SGBD_BASE.executaSQL(SQL,"query");
        //System.out.println();
        if(r==null){
            //System.out.println("Nao Existia projeto");
            this.SGBD_BASE.executaSQL("INSERT INTO Projetos VALUES ('"+Projeto+"','0');","update");
            Versao=0;
        }else{
            try {
                ResultSet rs=r.getResultSet();
                rs.first();
                Versao=rs.getInt("MAX(Versao)");
                Versao++;
            } catch (SQLException ex) {
                //ex.printStackTrace();
                new Error("SQL Error "+ex.getErrorCode()+"\n"+ex.getMessage());
            }
        }
        
        
        this.SGBD_BASE.executaSQL("DELETE FROM Arestas WHERE Projeto='"+Projeto+"' AND Versao='"+Integer.toString(Versao)+"';","update");
        this.SGBD_BASE.executaSQL("DELETE FROM Atributos_Entidade WHERE Projeto='"+Projeto+"' AND Versao='"+Integer.toString(Versao)+"';","update");
        this.SGBD_BASE.executaSQL("DELETE FROM Atributos_Relacionamento WHERE Projeto='"+Projeto+"' AND Versao='"+Integer.toString(Versao)+"';","update");
        this.SGBD_BASE.executaSQL("DELETE FROM Entidades WHERE Projeto='"+Projeto+"' AND Versao='"+Integer.toString(Versao)+"';","update");
        this.SGBD_BASE.executaSQL("DELETE FROM Herancas WHERE Projeto='"+Projeto+"' AND Versao='"+Integer.toString(Versao)+"';","update");
        this.SGBD_BASE.executaSQL("DELETE FROM Relacionamentos WHERE Projeto='"+Projeto+"' AND Versao='"+Integer.toString(Versao)+"';","update");
        
        int i=0;
        while(i<edges.length){
            if(edges[i].getClass()==Entidade.class ){
                Entidades.add((Entidade)edges[i]);
                exportEntidade((Entidade)edges[i],Entidades.size());
                
                
            }else if(edges[i].getClass()==Relacionamento.class ){
                Relacionamentos.add((Relacionamento)edges[i]);
                exportRelacionamento((Relacionamento)edges[i],Relacionamentos.size());
                
                
            }else if(edges[i].getClass()==Heranca.class ){
                Herancas.add((Heranca)edges[i]);
                exportHeranca((Heranca)edges[i],Herancas.size());
                
                
            }
            i++;
        }
        
        
        Aresta a;
        edges=graph.getGraphLayoutCache().getCells(false,false,false,true);
        i=0;
        boolean Total;
        boolean Heranca;
        int Source=-1;
        int Target=-1;
        String Source_type=null;
        String Target_type=null;
        
        
        SQL="INSERT INTO Arestas ( Projeto , Versao , ID , Heranca , Total , Source , Target , Source_type , Target_type , Min , Max ) VALUES ";
        
        while(i<edges.length){
            a=(Aresta)edges[i];
            Total=a.isTotal();
            Heranca=a.isHeranca();
            if(((DefaultPort)a.getSource()).getUserObject().getClass()==Entidade.class){
                Source=Entidades.indexOf(((DefaultPort)a.getSource()).getUserObject());
                Source_type="Entidade";
            }else if(((DefaultPort)a.getSource()).getUserObject().getClass()==Relacionamento.class){
                Source=Relacionamentos.indexOf(((DefaultPort)a.getSource()).getUserObject());
                Source_type="Relacionamento";
            }else if(((DefaultPort)a.getSource()).getUserObject().getClass()==Heranca.class){
                Source=Herancas.indexOf(((DefaultPort)a.getSource()).getUserObject());
                Source_type="Heranca";
            }
            if(((DefaultPort)a.getTarget()).getUserObject().getClass()==Entidade.class){
                Target=Entidades.indexOf(((DefaultPort)a.getTarget()).getUserObject());
                Target_type="Entidade";
            }else if(((DefaultPort)a.getTarget()).getUserObject().getClass()==Relacionamento.class){
                Target=Relacionamentos.indexOf(((DefaultPort)a.getTarget()).getUserObject());
                Target_type="Relacionamento";
            }else if(((DefaultPort)a.getTarget()).getUserObject().getClass()==Heranca.class){
                Target=Herancas.indexOf(((DefaultPort)a.getTarget()).getUserObject());
                Target_type="Heranca";
            }
            if(i!=0)
                SQL+=",";
            
            SQL+="('"+Projeto+"','"+Integer.toString(Versao)+"','"+Integer.toString(i)+"','"+boo2str(Heranca)+"','"+boo2str(Total)+"','"
                    +Integer.toString(Source)+"','"+Integer.toString(Target)+"','"+Source_type+"','"+Target_type
                    +"','"+Integer.toString(a.getMin())+"','"+Integer.toString(a.getMax())+"')";
            
            i++;
        }
        if(edges.length>0){
            SQL+=";";
            this.SGBD_BASE.executaSQL(SQL,"update");
//            System.out.println(SQL);
//            if(this.SGBD_BASE.executaSQL(SQL,"update")==null){
//                new Error ("Crepalde retorna null");
//            }
        }
        
        SQL="INSERT INTO Alvos VALUES ('"+Projeto+"','"+Integer.toString(Versao)+"','"
                +SGBD_ALVO.getSGBD()+"','"+SGBD_ALVO.getServidor()+"','"+SGBD_ALVO.getPorta()
                +"','"+SGBD_ALVO.getBD()+"','"+SGBD_ALVO.getUsuario()+"');";
        this.SGBD_BASE.executaSQL(SQL,"update");
        //System.out.println(SQL);
        
        
        //SQL="UPDATE Projetos SET Versao='"+Integer.toString(Versao)+"' WHERE Nome='"+Projeto+"';";
        SQL="INSERT INTO Projetos VALUES ('"+Projeto+"','"+Integer.toString(Versao)+"');";
        this.SGBD_BASE.executaSQL(SQL,"update");
        
        
        
        r=this.SGBD_BASE.executaSQL("SELECT MAX(Versao) FROM Projetos WHERE Projeto='"+Projeto+"';","query");
        if(r!=null){
            try {
                ResultSet rs=r.getResultSet();
                rs.first();
                Versao=rs.getInt("MAX(Versao)");
                System.out.println("Salvo no BD com sucesso a versao "+new Integer(Versao).toString()+"\n");
            } catch (SQLException ex) {
                //ex.printStackTrace();
                new Error("SQL Error "+ex.getErrorCode()+"\n"+ex.getMessage());
            }
    }
    }
    
    public boolean exportEntidade(Entidade e,int ID){
        String Nome=graph.convertValueToString(e);
        boolean Fraca=e.isFraca();
        
        Rectangle2D size=GraphConstants.getBounds(e.getAttributes());
        double x=size.getX();
        double y=size.getY();
        double h=size.getHeight();
        double w=size.getWidth();
        String SQL="INSERT INTO Entidades ( Projeto , Versao , ID , Nome , Fraca , x , y , h , w ) VALUES (";// 
        SQL+="'"+Projeto+"','"+Integer.toString(Versao)+"','"+Integer.toString(ID)+"','"+Nome+"','"+boo2str(Fraca)+"','"
                    +Double.toString(x)+"','"+Double.toString(y)+"','"+Double.toString(h)+"','"+Double.toString(w)+"');";
        //System.out.println(SQL);
        this.SGBD_BASE.executaSQL(SQL,"update");
//            if(this.SGBD_BASE.executaSQL(SQL,"update").getRecordCount()>0){
//                new Error("Erro ao exportar entidade.");
//                return false;
//            }
        return exportAtributosEntidade(e,ID);
    }
    public boolean exportRelacionamento(Relacionamento e,int ID){
        String Nome=graph.convertValueToString(e);
        boolean Associativa=e.isAssociativa();
        boolean Total=e.isTotal();
        
        Rectangle2D size=GraphConstants.getBounds(e.getAttributes());
        double x=size.getX();
        double y=size.getY();
        double h=size.getHeight();
        double w=size.getWidth();
        
        String SQL="INSERT INTO Relacionamentos ( Projeto , Versao , ID , Nome , Associativa , Total , x , y , h , w ) VALUES (";// ( 'Projeto' , 'Versao' , 'ID' , 'Nome' , 'Fraca' , 'x' , 'y' , 'h' , 'w' )
        SQL+="'"+Projeto+"','"+Integer.toString(Versao)+"','"+Integer.toString(ID)+"','"+Nome+"','"+boo2str(Associativa)+"','"+boo2str(Total)+"','"
                    +Double.toString(x)+"','"+Double.toString(y)+"','"+Double.toString(h)+"','"+Double.toString(w)+"');";
        //System.out.println(SQL);
        this.SGBD_BASE.executaSQL(SQL,"update");
//            if(this.SGBD_BASE.executaSQL(SQL,"update").getRecordCount()>0){
//                new Error("Erro ao exportar relacionamento.");
//                return false;
//            }
        return exportAtributosRelacionamento(e,ID);
        
    }
    public boolean exportHeranca(Heranca e,int ID){
        boolean Disjunta=e.isDisjunta();
        boolean Total=e.isTotal();
        
        Rectangle2D size=GraphConstants.getBounds(e.getAttributes());
        double x=size.getX();
        double y=size.getY();
        double h=size.getHeight();
        double w=size.getWidth();
        
        String SQL="INSERT INTO Herancas ( Projeto , Versao , ID , Disjunta , Total , x , y , h , w ) VALUES (";// ( `Projeto` , `Versao` , `ID` , `Nome` , `Fraca` , `x` , `y` , `h` , `w` )
        SQL+="'"+Projeto+"','"+Integer.toString(Versao)+"','"+Integer.toString(ID)+"','"+boo2str(Disjunta)+"','"+boo2str(Total)+"','"
                    +Double.toString(x)+"','"+Double.toString(y)+"','"+Double.toString(h)+"','"+Double.toString(w)+"');";
        //System.out.println(SQL);
        this.SGBD_BASE.executaSQL(SQL,"update");
//            if(this.SGBD_BASE.executaSQL(SQL,"update").getRecordCount()>0){
//                new Error("Erro ao exportar heranca.");
//                return false;
//            }
        return true;
        
    }
    
    public boolean exportAtributosEntidade(Entidade b,int Entidade){
        Object[] a=b.valuesArrayAtributosPrimos();
        int i=0;
        int j=0;
        int ID=0;
        Object[] d;
        String SQL="INSERT INTO Atributos_Entidade VALUES ";
        while(i<a.length){
            if(ID!=0)
                SQL+="'),";
            d=((Atributo)a[i]).getArray();
            j=0;
            SQL+="('"+Projeto+"','"+Integer.toString(Versao)+"','"+Integer.toString(Entidade)+"','"+Integer.toString(ID)+"','true";
            while(j<d.length){
                SQL+="','"+d[j].toString();
                j++;
            }
            ID++;
            i++;
        }
        i=0;
        a=b.valuesArrayAtributos();
        while(i<a.length){
            if(ID!=0)
                SQL+="'),";
            d=((Atributo)a[i]).getArray();
            j=0;
            SQL+="('"+Projeto+"','"+Integer.toString(Versao)+"','"+Integer.toString(Entidade)+"','"+Integer.toString(ID)+"','false";
            while(j<d.length){
                SQL+="','"+d[j].toString();
                j++;
            }
            ID++;
            i++;
        }
        SQL+="');";
        //System.out.println(SQL);
        this.SGBD_BASE.executaSQL(SQL,"update");
//        if(ID!=0){
//            if(this.SGBD_BASE.executaSQL(SQL,"update").getRecordCount()>0){
//                new Error("Erro ao exportar atributos de uma entidade.");
//                return false;
//            }
//        }
        return true;
    }
    public boolean exportAtributosRelacionamento(Relacionamento b,int Relacionamento){
        Object[] a=b.valuesArrayAtributosPrimos();
        int i=0;
        int j=0;
        int ID=0;
        Object[] d;
        String SQL="INSERT INTO Atributos_Relacionamento VALUES ";
        while(i<a.length){
            if(ID!=0)
                SQL+="'),";
            d=((Atributo)a[i]).getArray();
            j=0;
            SQL+="('"+Projeto+"','"+Integer.toString(Versao)+"','"+Integer.toString(Relacionamento)+"','"+Integer.toString(ID)+"','true";
            while(j<d.length){
                SQL+="','"+d[j].toString();
                j++;
            }
            ID++;
            i++;
        }
        i=0;
        a=b.valuesArrayAtributos();
        while(i<a.length){
            if(ID!=0)
                SQL+="'),";
            d=((Atributo)a[i]).getArray();
            j=0;
            SQL+="('"+Projeto+"','"+Integer.toString(Versao)+"','"+Integer.toString(Relacionamento)+"','"+Integer.toString(ID)+"','false";
            while(j<d.length){
                SQL+="','"+d[j].toString();
                j++;
            }
            ID++;
            i++;
        }
        SQL+="');\n";
        this.SGBD_BASE.executaSQL(SQL,"update");
        //System.out.println(SQL);
//        if(ID!=0){
//            if(this.SGBD_BASE.executaSQL(SQL,"update").getRecordCount()>0){
//                new Error("Erro ao exportar atributos de um relacionamento.");
//                return false;
//            }
//        }
        return true;
        
    }
    
    
}
